/*
 *  Copyright (C) 2010 Francesco Boffa (aka AlfaOmega08)
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package Gui;

import java.awt.event.*;
import java.util.*;

public class Languages {
	Hashtable<String, String[]> lang = new Hashtable<String, String[]>();
	javax.swing.ButtonGroup bg = new javax.swing.ButtonGroup();
	Vector<javax.swing.JRadioButtonMenuItem> buttons = new Vector<javax.swing.JRadioButtonMenuItem>();

	public Languages() {
		lang.put("English", new String[] { "en", "US" });
		lang.put("Italiano", new String[] { "it", "IT" });
	}

	public void InitMenu(javax.swing.JMenu m) {
		Set<String> set = lang.keySet();
		Iterator<String> itr = set.iterator();
		while (itr.hasNext()) {
			String curLang = itr.next();

			javax.swing.JRadioButtonMenuItem menuEntry = new javax.swing.JRadioButtonMenuItem();
			menuEntry.setText(curLang);
			if (curLang.equals(Engine.Config.getConfig("LongLanguage"))) {
				menuEntry.setSelected(true);
			}

			buttons.add(menuEntry);
			bg.add(menuEntry);
			m.add(menuEntry);
		}
	}

	public void setActionListeners(ActionListener listener) {
		for (int i = 0; i < buttons.size(); i++)
			buttons.get(i).addActionListener(listener);
	}

	public String getLanguage(String longName) {
		return lang.get(longName)[0];
	}

	public String getCountry(String longName) {
		return lang.get(longName)[1];
	}
}
